var count=0;
var m=0;
var list;
$(function() {

   if(!window.ActiveXObject){
        $("#zhishi").css("margin-left","4px");
        $("#footht").css("height","20px");
    }else{
        $("#zhishi").css("padding-left","4px");
    }
   initZYbg();
   InitZS();
      $(window).resize(function() {
			    initZYbg();
			   });
});
function initZYbg(){ 
	//alert(document.body.clientWidth);
     if(document.body.clientWidth<957){
	        $("#mainleft").width(0);
	        $("#mainright").width(0);
	        $("#mainleft").css("display","none");
		    $("#mainright").css("display","none");
        }else{
	       if(!window.ActiveXObject){
		        var wid=($(document).width()-953)/2;
		        $("#mainleft").width(wid);
		        $("#mainright").width(wid);
		        $("#mainleft").css("display","block");
		        $("#mainright").css("display","block");
		    }else{
		        var wid=($(document).width()-974)/2;
		        if(wid>0){
		        	$("#mainleft").width(wid);
			        $("#mainright").width(wid);
			        $("#mainleft").css("display","block");
			        $("#mainright").css("display","block");
		        }
		    }
        }
}
//初始化知识
function InitZS(){
	 $("#zhishi").html("");
	IndexDwr.CateListAll(function(data){
		list=data;
		count=data.length;	
		var zscount=parseInt(count/3)+(count%3>0?1:0);
		if(!window.ActiveXObject){
			if(zscount==3){
				$("#tgTXT").height(790);
			}
			if(zscount>3){
				$("#tgTXT").height((zscount-3)*256+790);
			}
		}
		if(count>0&&m<count){
			IndexDwr.getList(1,list[m].id,list[m].name,returnZhiShi);
			m++;
		}
	});
}
function returnZhiShi(data){
	   var zhishi="";
	   var trs="";
	   var pages=pageTemp.replace("#CNAME#",data.temp).replace("#Total#",data.totalPages==0?1:data.totalPages)
	                  .replace("#Curcent#",data.pageNo);
	   if(data.pageNo==1){
		   pages=pages.replace("#ClassPre#","disprepage").replace("#ClickPre#","");
	   }else{
		    pages=pages.replace("#ClassPre#","prepage").replace("#ClickPre#","onclick='ChengePage("+(data.pageNo-1)+","+data.temp1+",\""+data.temp+"\")'");
	   }
       if(data.pageNo==data.totalPages||data.totalPages==0){
		   pages=pages.replace("#ClassNext#","disnextpage").replace("#ClickNext#","");
	   }else{
		    pages=pages.replace("#ClassNext#","nextpage").replace("#ClickNext#","onclick='ChengePage("+(data.pageNo+1)+","+data.temp1+",\""+data.temp+"\")'");
	   }
	   zhishi=template.replace("#Page#",pages).replace("#CID#",data.temp1)
	                  .replace("#CID#",data.temp1).replace("#CID#",data.temp1);
	   for(var i=0;i<data.knows.length;i++){
		   trs=trs+trsTemp.replace("#Title#",getByteVal(data.knows[i].title,40)).replace("#Type#",data.knows[i].type+"")
		                  .replace("#ID#",data.knows[i].id);
		   if(data.knows[i].type>0){
			   trs=trs.replace("#IMG#", '<a href="download.do?id='+data.knows[i].id+'" target="_blank"><img alt="" style="border:0px;" src="img/gl/format/'+data.knows[i].type+'.gif"/></a>')
		   }else{
			   trs=trs.replace("#IMG#","");
		   }
	   }
	   zhishi=zhishi.replace("#TRS#", trs);
	   $("#zhishi").append(zhishi);
	   if(count>0&&m<count){
			IndexDwr.getList(1,list[m].id,list[m].name,returnZhiShi);
			m++;
		}
	   initZYbg();
	    if (isIE6) {  
	      $(".zhishis").css("margin-right","1px");
	    } 
}
function ChengePage(pageNo,cid,cname){
    IndexDwr.getList(pageNo,cid,cname,function(data){
	   var trs="";
	   var pages=pageTemp.replace("#CNAME#",data.temp).replace("#Total#",data.totalPages==0?1:data.totalPages)
	                  .replace("#Curcent#",data.pageNo);
	   if(data.pageNo==1){
		   pages=pages.replace("#ClassPre#","disprepage").replace("#ClickPre#","");
	   }else{
		    pages=pages.replace("#ClassPre#","prepage").replace("#ClickPre#","onclick='ChengePage("+(data.pageNo-1)+","+data.temp1+",\""+data.temp+"\")'");
	   }
       if(data.pageNo==data.totalPages||data.totalPages==0){
		   pages=pages.replace("#ClassNext#","disnextpage").replace("#ClickNext#","");
	   }else{
		    pages=pages.replace("#ClassNext#","nextpage").replace("#ClickNext#","onclick='ChengePage("+(data.pageNo+1)+","+data.temp1+",\""+data.temp+"\")'");
	   }
       $("#Tr_"+cid).html(pages);
       for(var i=0;i<data.knows.length;i++){
		   trs=trs+trsTemp.replace("#Title#",getByteVal(data.knows[i].title,40)).replace("#Type#",data.knows[i].type+"")
		                  .replace("#ID#",data.knows[i].id);
		   if(data.knows[i].type>0){
			   trs=trs.replace("#IMG#", '<a href="download.do?id='+data.knows[i].id+'" target="_blank"><img alt="" style="border:0px;" src="img/gl/format/'+data.knows[i].type+'.gif"/></a>')
		   }else{
			   trs=trs.replace("#IMG#","");
		   }
	   }
       $("#Tbl_"+cid).html(trs);
    });	
}

var template=' <div class="zhishis"> '+
   ' <div class="zszuo"></div> '+
   ' <div class="zszhong">'+
   '   <div class="zstitletop">'+
   '      <table cellpadding="0" cellspacing="0" style="float:left;margin:0px;">'+
   '        <tr id="Tr_#CID#">'+
   '           #Page#'+
	'       </tr>'+
    '     </table>'+
    '  </div>'+
    '  <div class="zsmain">'+
    '    <table  cellpadding="0" cellspacing="0" style="float:left;margin:0px;">'+
    '      <tbody id="Tbl_#CID#">#TRS# </tbody>'+
    '   </table> '+
    '  </div>'+
    '  <div class="zsmore">'+
    '    <a href="zslist.do?cid=#CID#" target="_blank"><img style="border:0px;" src="img/qt/more.jpg"/></a>'+
    '  </div>'+
    '</div>'+
    '<div class="zsyou"></div>'+
   '</div>';

var trsTemp='      <tr>'+
'       <td class="zsdot"></td>'+
'       <td class="zstitle">'+
'        <a href="zsdetail.do?id=#ID#" target="_blank">#Title#</a>'+
'       </td>'+
'       <td class="img">'+
'        #IMG#'+
'       </td>'+
'      </tr>';
var pageTemp=   ' <td class="zstt">#CNAME#</td>'+
	'           <td class="zstotal">共#Total#页 第#Curcent#页</td>'+
	'           <td class="zspage" style="">'+
	'               <div class="#ClassNext#" #ClickNext# ></div>'+
	'               <div class="midpage"  ></div>'+
	'               <div class="#ClassPre#" #ClickPre#></div>'+
	'           </td>';
